Skip to content

fix(codegen-ts): keep credentials out of generated grids - #616

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-ui-credential-columns
Nov 20, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-ui-credential-columns

Conversation

@dmealing

@dmealing dmealing commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Generated TanStack and Angular grids no longer emit a column for a credential (view.password), even when @columns names it. A @defaultSortField naming a credential now resolves to no initial sort. On a TPH base's grid, a credential marked by any subtype counts. The shared credentialFieldNames() helper in codegen-ts backs this, and resolveGridDefaultSort() takes an optional root to check it.
  • A @filter preset over a credential, at any and / or depth, now fails meta gen and names the layout and field. Before, it emitted a filter the server refuses on every request.
  • The agent UI page, the runtime buildGrid() in runtime-web, and the docs and CHANGELOG follow the same rules. The agent UI page marks a credential as form-excluded. Value-object (nested) credentials stay a documented known limit.
Validation

Risk Assessment

✅ Low: The change is bounded and consistent: credential columns and initial sorts are dropped in every generated or runtime grid tier, with execution-based tests, and the previously flagged runtime-web sibling is now fixed.

Testing

Drove two scenarios live through the real meta gen CLI (run from source with bun) on synthetic scratch projects, then removed the scratch. S1: a plain entity with a password field generates a grid with only email (pinHash dropped from columns and default sort) and agent/ui.md lists columns: email with no default sort. S2 (adversarial TPH): the Auth base grid drops both the subtype-only credential pin and the sibling-marked code, in Auth.columns.tsx and in the agent page for all three grids, and keeps the non-credential type and id columns. Focused credential tests (10) pass. Overall: pass. Not driven: the runtime-web buildGrid twin (outside the generated-UI intent) and the React/Angular form generators (not wired in these projects; existing per-object form rule unchanged). Note: the BridgeAuth code form row shows as a plain text field, consistent with the per-object form rule.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
S1 plain entity: a view.password field is not a generated grid column, not the default sort, and not listed in agent/ui.md (synthetic Account via meta gen CLI) ✅ pass live meta gen run from source in a scratch project; output src/generated/Account.columns.tsx has only the email column and no initialSort; docs/generated/agent/ui.md grid section reads - columns: \emai…
S2 adversarial TPH: subtype-only credential (pin) and column a sibling marks as credential (code) are dropped from the TPH base grid and every agent grid section (synthetic Auth/BridgeAuth/CouponAuth… ✅ pass live meta gen run from source; Auth.columns.tsx lists only type and id; agent ui.md shows - columns: \type`, `id`` for Auth, BridgeAuth and CouponAuth; grep for pin/code in grid output finds nothing…
Evidence: S1 plain entity: generated grid columns file (pinHash absent)
// @generated by @metaobjectsdev/codegen-ts-tanstack — hand edits are kept by a three-way merge on regeneration; meta verify --codegen checks only the generated parts.
// Source metadata: Account (Account)
import type { Account as AccountRow } from "./Account.js";

import type { ColumnDef } from "@tanstack/react-table";

export const accountDefaultGrid = {
  name: "default",
  pageSize: 25,
  filterable: false,
};

export const accountDefaultColumns: ColumnDef<AccountRow>[] = [
  {
    id: "email",
    accessorKey: "email",
    header: "Email",
    meta: { view: "text", sortable: true },
  },
];
Evidence: S1 plain entity: agent ui.md grid section
<!-- @generated by @metaobjectsdev/codegen-ts — DO NOT EDIT. -->

# UI

What the generated forms and grids already are. Read it before changing a form, a grid or a filter — the generated `.tsx` is the disposable artifact, this is what produced it.

- Every row here is the SAME derivation the runtime reads — `buildEntityUiDescriptor`, which is emitted as the `<Entity>` const in `<Entity>.meta.ts` and consumed by `useEntityForm`. Changing the metadata changes both. A READ-ONLY projection's const carries the subset that applies to it (no form, so no rules and no HTML type) plus the `dbCol` only a view-backed const has.
- `Control` is what the FORM renders. A field declaring several views is described by the one named `form`; a `field.object` whose `@objectRef` resolves is not an input at all but a nested sub-form over that value object, and says so.
- `Filter` / `Sort` are what the generated LIST endpoint accepts. `@sortable` defaults to `@filterable`, and the resolved answer is what is shown.

## `live::acct::Account`

Endpoint `/accounts`.

| Field | Label | Control | HTML type | Rules | Excluded | Filter | Sort |
|---|---|---|---|---|---|---|---|
| `id` | Id | `number` | `number` |  |  |  |  |
| `email` | Email | `text` | `text` |  |  | yes | yes |
| `pinHash` | Pin Hash | `password` | `password` |  | yes |  |  |

**Grid `default`**

- columns: `email`
Evidence: S2 TPH: generated Auth grid columns file (pin and code absent)
// @generated by @metaobjectsdev/codegen-ts-tanstack — hand edits are kept by a three-way merge on regeneration; meta verify --codegen checks only the generated parts.
// Source metadata: Auth (Auth)
import type { AuthRow } from "./Auth.js";

import type { ColumnDef } from "@tanstack/react-table";

export const authDefaultGrid = {
  name: "default",
  pageSize: 25,
  filterable: false,
};

export const authDefaultColumns: ColumnDef<AuthRow>[] = [
  {
    id: "type",
    accessorKey: "type",
    header: "Type",
    meta: { view: "text", sortable: false, renderer: "badge" },
  },
  {
    id: "id",
    accessorKey: "id",
    header: "Id",
    meta: { view: "text", sortable: false },
  },
];
Evidence: S2 TPH: agent ui.md (grid columns type,id for all three objects)
<!-- @generated by @metaobjectsdev/codegen-ts — DO NOT EDIT. -->

# UI

What the generated forms and grids already are. Read it before changing a form, a grid or a filter — the generated `.tsx` is the disposable artifact, this is what produced it.

- Every row here is the SAME derivation the runtime reads — `buildEntityUiDescriptor`, which is emitted as the `<Entity>` const in `<Entity>.meta.ts` and consumed by `useEntityForm`. Changing the metadata changes both. A READ-ONLY projection's const carries the subset that applies to it (no form, so no rules and no HTML type) plus the `dbCol` only a view-backed const has.
- `Control` is what the FORM renders. A field declaring several views is described by the one named `form`; a `field.object` whose `@objectRef` resolves is not an input at all but a nested sub-form over that value object, and says so.
- `Filter` / `Sort` are what the generated LIST endpoint accepts. `@sortable` defaults to `@filterable`, and the resolved answer is what is shown.

## `live::auth::Auth`

Endpoint `/auths` — **no form is generated** for a discriminator base — its own mount is list/get only, and each concrete subtype below has its own form. The fields below describe the grid and the filters.

| Field | Label | Control | HTML type | Rules | Excluded | Filter | Sort |
|---|---|---|---|---|---|---|---|
| `type` | Type | `dropdown` |  |  |  |  |  |
| `id` | Id | `number` | `number` |  |  |  |  |

**Grid `default`**

- columns: `type`, `id`

## `live::auth::BridgeAuth`

Endpoint `/auths/bridge`.

| Field | Label | Control | HTML type | Rules | Excluded | Filter | Sort |
|---|---|---|---|---|---|---|---|
| `type` | Type | `dropdown` |  |  |  |  |  |
| `id` | Id | `number` | `number` |  |  |  |  |
| `pin` | Pin | `password` | `password` |  | yes |  |  |
| `code` | Code | `text` | `text` |  |  |  |  |

**Grid `default`**

- columns: `type`, `id`

## `live::auth::CouponAuth`

Endpoint `/auths/coupon`.

| Field | Label | Control | HTML type | Rules | Excluded | Filter | Sort |
|---|---|---|---|---|---|---|---|
| `type` | Type | `dropdown` |  |  |  |  |  |
| `id` | Id | `number` | `number` |  |  |  |  |
| `code` | Code | `password` | `password` |  | yes |  |  |

**Grid `default`**

- columns: `type`, `id`
Evidence: S1/S2 input metadata
{ "metadata.root": { "package": "live::acct", "children": [
  { "object.entity": { "name": "Account", "children": [
    { "source.rdb": { "@table": "account" } },
    { "field.long": { "name": "id" } },
    { "identity.primary": { "name": "pk", "@fields": ["id"], "@generation": "increment" } },
    { "field.string": { "name": "email", "@filterable": true, "@sortable": true } },
    { "field.string": { "name": "pinHash", "@filterable": true, "@sortable": true, "children": [ { "view.password": {} } ] } },
    { "layout.dataGrid": { "name": "default", "@columns": ["email", "pinHash"], "@defaultSortField": "pinHash", "@defaultSortOrder": "asc" } }
  ]}}
]}}
  • Outcome: 🔧 2 issues found → auto-fixed ✅ across 2 runs (25m25s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 2 issues found → auto-fixed ✅
  • ⚠️ server/typescript/packages/codegen-ts/src/generators/agent-ui-page.ts:192 - Live meta gen (agentDocsFile) on a TPH model: agent/ui.md Auth grid lists columns: type, id, pin, code and CouponAuth grid lists pin. The generated Auth.columns.tsx drops pin and code. Cause: gridSection (line 192) calls credentialFieldNames(obj, root) on the base only; that hierarchy misses subtype-only credentials (pin) and sibling-marked shared columns (code). Probe: credentialFieldNames(Auth, root) = [], BridgeAuth = [pin, code], CouponAuth = [code]. Fix: build the credential set as the union over tphHierarchy(obj, root), as gridCredentialNames does in the tanstack tier. Also add a live-equivalent assertion on a TPH base in the codegen-ts test. Simple, about 5 lines in 1 file. Repair is within intent (UI-side leak), not a policy change.
  • 🚨 live validation verdict: no-go (3 of 4 scenarios were driven live against the product); failed: S3 Adversarial TPH: subtype-only credential and a column that a sibling subtype marks as credential are dropped from the TPH base grid; agent page must agree (Auth model)
  • Live validation: ❌ no-go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
S1 Plain entity grid: a credential named by @columns and @defaultSortField is not a grid column and gives no initial sort (meta gen, Account model) ✅ pass live grid-leak-before-after.txt; base/Account.columns.tsx has pinHash column and defaultSort; fixed/Account.columns.tsx and fixed/Account.grid.ts have no pinHash
S2 Generated form skips a credential field, and the agent UI page marks it excluded (Account model) ✅ pass live fixed/Account.form.tsx has 0 pinHash occurrences; fixed/agent-ui.md Account row pinHash shows Excluded=yes with no filter or sort flag
S3 Adversarial TPH: subtype-only credential and a column that a sibling subtype marks as credential are dropped from the TPH base grid; agent page must agree (Auth model) ❌ fail live fixed/Auth.columns.tsx drops pin and code (pass); fixed/agent-ui.md lists columns: type, id, pin, code on the Auth grid and pin on CouponAuth's grid (fail)
S4 runtime-web buildGrid never returns a credential column or sort (client-side twin) ⏸️ untested no Only the focused unit test drives this path. Live driving needs a browser-side runtime with a fetcher and an entity model, which is out of scope for this generated-UI intent. Not a live pass.
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline (given): scripts/ci-local.sh --affected --strict-toolchains passed at 1c1e5ac16; not re-run (no source change in this phase)
  • bun {run-worktree}/server/typescript/packages/cli/bin/meta.ts gen in /mnt/scratch/cred-validate (target commit, Account + Session + TPH Auth model, generators entityFile, queriesFile, routesFile, formFile, tanstackQuery, tanstackGrid, tanstackGridHook, barrel, agentDocsFile)
  • Same model regenerated with the base b78da0f29 CLI and packages (git archive, isolated node_modules) in /mnt/scratch/base-proj, as the before-fix reproduction
  • Diff of generated Account.columns.tsx, Account.grid.ts, Account.form.tsx and Auth.columns.tsx, base vs fixed; agent/ui.md read from both
  • bun test test/credential-grid-column.test.ts in codegen-ts-tanstack (7 pass), codegen-ts-angular (3 pass)
  • bun test test/agent-ui-credential.test.ts in codegen-ts (2 pass)
  • bun test test/grid-from-metadata.test.ts in client/web/packages/runtime-web (13 pass)
  • Scenario-to-command mapping: S1 and S2 driven by meta gen; S3 is the TPH case through the same meta gen; S4 is covered by focused test only

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
S1 plain entity: a view.password field is not a generated grid column, not the default sort, and not listed in agent/ui.md (synthetic Account via meta gen CLI) ✅ pass live meta gen run from source in a scratch project; output src/generated/Account.columns.tsx has only the email column and no initialSort; docs/generated/agent/ui.md grid section reads - columns: \emai…
S2 adversarial TPH: subtype-only credential (pin) and column a sibling marks as credential (code) are dropped from the TPH base grid and every agent grid section (synthetic Auth/BridgeAuth/CouponAuth… ✅ pass live meta gen run from source; Auth.columns.tsx lists only type and id; agent ui.md shows - columns: \type`, `id`` for Auth, BridgeAuth and CouponAuth; grep for pin/code in grid output finds nothing…
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains (already passed at target commit 1ff07b0df; not re-run, no source changes in this turn)
  • Live S1: bun server/typescript/packages/cli/bin/meta.ts gen in a scratch project with a plain Account entity (email + pinHash with view.password, grid @columns [email,pinHash], @defaultSortField pinHash), generators tanstackGrid + agentDocsFile
  • Live S2 (adversarial TPH): meta gen on Auth/BridgeAuth/CouponAuth (pin is password on BridgeAuth only; code is password on CouponAuth only, plain on BridgeAuth)
  • bun test packages/codegen-ts/test/agent-ui-credential.test.ts packages/codegen-ts-tanstack/test/credential-grid-column.test.ts in server/typescript (10 pass, 0 fail)
  • Evidence recorded as s1-plain and s2-tph; scratch project under DEV_SCRATCH removed
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ial sort and filter presets

The generated forms skipped a view.password field, but the TanStack and Angular grids emitted a
column for it whenever a layout.dataGrid named it (or listed no @columns), and a
@defaultSortField naming one became the grid's initial sort. Columns are now dropped and the
sort resolves to none in every tier, counting a column any TPH subtype marks as a credential on
a base's polymorphic grid. A @filter preset over a credential fails meta gen instead of being
emitted. The agent UI page marks a credential as excluded and leaves it out of grid columns and
default sort.
@dmealing
dmealing merged commit 333ccc6 into main Nov 20, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-ui-credential-columns branch November 20, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant